package algotithm.leetcode.bit.test477;

/**
 * @author 25068
 * @Date 2021/5/28 8:57
 * @Title 477. 汉明距离总和
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {4,14,2};
        int res = solution.totalHammingDistance(nums);
        System.out.println(res);
    }

    public int totalHammingDistance(int[] nums) {
        int n = nums.length;
        int res = 0;
        for (int i = 0; i < 30; i++) {
            int c = 0;
            for (int val : nums) {
                c += (val >> i) & 1;
            }
            res += c * (n - c);
        }
        return res;
    }

}
